package valueObject
{
	import com.greensock.TweenLite;
	
	import config.Constant;
	import config.EmbedConstant;
	
	import event.EventManager;
	import event.GameEvent;
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;

	/**
	 *怪物vo 
	 * @author SXT
	 */
	public class MonsterVO extends ExpertVO implements ITarget, IVO
	{
		/**
		 *防御 
		 */
		public var defense:int;
		/**
		 *减速 
		 */
		public var slow:int;
		/**
		 *燃烧、中毒 
		 */
		public var burn:int;
		/**
		 *当前的hp 
		 */		
		public var cutHp:int;
		/**
		 *血条 
		 */		
		private var hpBar:Shape;
		/**
		 *满血条 
		 */
		private var hpMaxBar:Shape;
		/**
		 * 朝向 
		 */		
		private var diraction:int;
		/**
		 *是否在活动状态 
		 */
		public var isActivity:Boolean = false;
		/**
		 *行走路径 
		 */		
		public var path:Array;
		/**
		 *路径的当前阶段 
		 */		
		public var cutPhase:int;
		/**
		 *路径端数 
		 */
		public var maxPhsae:int;
		
		private var  _mcid:String;
		/**
		 *临时存储距离用 
		 */		
		private var $tmpDistance:int;
		
		public function MonsterVO()
		{
			super();
			this.mouseChildren = false;
			this.mouseEnabled = false;
		}
		
		/**
		 *最大血条 
		 */
		private function initHpMaxBar():void
		{
			hpMaxBar = new Shape();
			hpMaxBar.graphics.beginFill(0xff0000);//sh.图形属性，填充颜色
			hpMaxBar.graphics.drawRect(0,0,mc.width,20);//sh.图形属性，画矩形
			hpMaxBar.graphics.endFill();
			hpMaxBar.width = mc.width;
			hpMaxBar.x = -8;
			hpMaxBar.y = -25;
			hpMaxBar.height = 6;
			this.addChild(hpMaxBar);//显示
		}
		
		/**
		 * 当前的血条
		 */
		private function initHpBar():void
		{
			initHpMaxBar();
			hpBar = new Shape();
			hpBar.graphics.beginFill(0x00ff00);//sh.图形属性，填充颜色
			hpBar.graphics.drawRect(0,0,mc.width - 2,16);//sh.图形属性，画矩形
			hpBar.graphics.endFill();
			hpBar.x = hpMaxBar.x + 1
			hpBar.y = hpMaxBar.y + 1;
			hpBar.width = hpMaxBar.width - 2;
			hpBar.height = hpMaxBar.height - 2;
			this.addChild(hpBar);//显示
		}
		
		public function setState(type:int):void{
			
		}
		
		public function setHp(num:int):void{
			cutHp = cutHp - num;
			hpBar.width = int((cutHp * (hpMaxBar.width / hp)));
		}
		
		public function release():void
		{
			if(cutHp <= 0){
				//血量大于0说明碰到了皇上,小于0说明是被打死了
				EventManager.instance.dispatchEvent(new GameEvent(GameEvent.CHANGE_POINT,{point:this.money}));
			}
			isActivity = false;
			mc.gotoAndStop(1);
		}

		/**
		 * @private
		 */
		public function set mcid(value:String):void
		{
			_mcid = "m"+value;
			try{
				m20001;
				m21001;
				m22001;
				var tmp:String = getQualifiedClassName(_mcid);
				var ClassReference:Class = getDefinitionByName(_mcid) as Class;
				mc = new ClassReference();
			}catch(e:Error){
				trace();
			}
			if(mc){
				addChild(mc);
				initHpBar();
			}
		}
		/**
		 *是否是最后的路径阶段 
		 * @return 
		 */
		public function isLast():Boolean
		{
//			trace("当前阶段"+(cutPhase+1)+":"+maxPhsae);
			if((cutPhase+1) == maxPhsae){
				return true;
			}
			return false;
		}
		
		public function estimate():Boolean
		{
			switch(path[cutPhase][2]){
				case 8:
				case 2:
					$tmpDistance = Math.abs(this.y - (path[cutPhase+1][1]*Constant.WH));
					break;
				case 6:
				case 4:
					$tmpDistance =  Math.abs(this.x - (path[cutPhase+1][0]*Constant.WH));
					break;
			}
//			trace($tmpDistance+":"+speed);//打印距离和速度
			if($tmpDistance < speed){
				return false;
			}
			return true;
		}
		/**
		 *设置朝向 
		 * @param param0
		 * 
		 */		
		public function setRotation(param:Number):void
		{
			TweenLite.to(mc,0.3,{rotation:param});
//			mc.rotation = param;
		}
		
		override public function get rotation():Number{
			return mc.rotation;
		}
	}
}